<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style></style>
  </head>

  <body>
    <script>
      const nameArr = [
        "王伟",
        "李娜",
        "张敏",
        "刘强",
        "陈静",
        "杨洋",
        "赵琳",
        "黄磊",
        "周雪",
        "吴芳",
        "徐杰",
        "孙丽",
        "马超",
        "朱婷",
        "胡军",
        "林涛",
        "郑凯",
        "高敏",
        "谢芳",
        "韩磊",
        "董洁",
        "曹阳",
        "邓超",
        "许婷",
        "潘勇",
        "钟华",
        "姜涛",
        "崔健",
        "范敏",
        "方芳",
        "白洁",
        "江涛",
        "孟伟",
        "康静",
        "侯杰",
        "龙芳",
        "石磊",
        "金鑫",
        "钱勇",
        "叶婷",
        "廖敏",
        "邹杰",
        "熊伟",
        "苏芳",
        "万强",
        "段静",
        "雷磊",
        "武芳",
        "尹杰",
        "黎敏",
        "谭伟",
        "邱芳",
        "秦杰",
        "杜静",
        "贺磊",
        "龚芳",
        "文杰",
        "牛敏",
        "温伟",
        "季芳",
        "成杰",
        "庞静",
        "关磊",
        "陆芳",
        "席杰",
        "鲁敏",
        "左伟",
        "程芳",
        "邢杰",
        "阮静",
        "柯磊",
        "莫芳",
        "申杰",
        "甘敏",
        "包伟",
        "宁芳",
        "尚杰",
        "焦敏",
        "向伟",
        "柳芳",
        "骆杰",
        "欧静",
        "耿磊",
        "舒芳",
        "牟杰",
        "卜敏",
        "费伟",
        "滕芳",
        "殷杰",
        "柏静",
        "梅磊",
        "盛芳",
        "曲杰",
        "翁敏",
        "冉伟",
        "柴芳",
        "骆杰",
        "华静",
        "管磊",
        "边芳",
        "桂杰",
        "解敏",
        "应伟",
        "乐芳",
        "薄杰",
        "山敏",
        "阳伟",
        "冷芳",
        "岑杰",
        "司徒静",
        "欧阳磊",
        "上官芳",
        "皇甫杰",
        "令狐敏",
        "诸葛伟",
        "司马芳",
        "尉迟杰",
        "申屠静",
        "慕容磊",
        "宇文芳",
        "王建华",
        "李淑芬",
        "张建军",
        "刘秀英",
        "陈国强",
        "杨玉兰",
        "赵国庆",
        "黄爱华",
        "周建军",
        "吴秀兰",
        "徐建国",
        "孙淑华",
        "马建军",
        "朱玉梅",
        "胡国栋",
        "林秀珍",
        "郑国梁",
        "高淑芬",
        "谢建军",
        "韩玉华",
        "董国辉",
        "曹淑英",
        "邓建军",
        "许玉芬",
        "潘国栋",
        "钟淑华",
        "姜建军",
        "崔玉梅",
        "范国梁",
        "方淑芬",
        "白建军",
        "江玉华",
        "孟国辉",
        "康淑英",
        "侯建军",
        "龙玉芬",
        "石国栋",
        "金淑华",
        "钱建军",
        "叶玉梅",
        "廖国梁",
        "邹淑芬",
        "熊建军",
        "苏玉华",
        "万国辉",
        "段淑英",
        "雷建军",
        "武玉芬",
        "尹国栋",
        "黎淑华",
        "谭建军",
        "邱玉梅",
        "秦国梁",
        "杜淑芬",
        "贺建军",
        "龚玉华",
        "文国辉",
        "牛淑英",
        "温建军",
        "季玉芬",
        "宋佳",
        "吕伟",
        "丁宁",
        "袁芳",
        "贾磊",
        "夏雪",
        "汪洋",
        "田静",
        "任杰",
        "顾敏",
        "邵华",
        "卢婷",
        "阎强",
        "余娟",
        "常浩",
        "乔丽",
        "易刚",
        "赖芳",
        "龚伟",
        "窦敏",
      ];

      console.log("nameArr", nameArr.length);

      const dataArr = [];

      nameArr.forEach((item) => {
        dataArr.push({
          name: item,
        });
      });

      console.log("dataArr", dataArr);

      const arr1 = [0.58, 0.35, 0.07, 0, 0];

      const allAnswerArr = [
        [0.58, 0.35, 0.07, 0, 0],
        [0.465, 0.415, 0.095, 0.02, 0.005],
        [0.535, 0.385, 0.075, 0.005, 0],
        [0.48, 0.465, 0.05, 0.005, 0],
        [0.49, 0.45, 0.05, 0.01, 0],
        [0.215, 0.33, 0.425, 0.03, 0],
        [0.26, 0.375, 0.205, 0.16, 0],
        [0.165, 0.2, 0.395, 0.23, 0.015],
        [0.125, 0.2, 0.405, 0.25, 0.02],
        [0.265, 0.475, 0.2, 0.055, 0.005],
        [0.41, 0.445, 0.135, 0.01, 0],
        [0.355, 0.485, 0.145, 0.01, 0],
        [0.205, 0.26, 0.37, 0.155, 0.001],
        [0.18, 0.255, 0.42, 0.145, 0],
        [0.375, 0.505, 0.105, 0.01, 0.005],
        [0.41, 0.495, 0.09, 0.005, 0],
        [0.09, 0.1, 0.295, 0.295, 0.22],
      ];

      start();

      function start() {
        allAnswerArr.forEach((answerArr, answerIndex) => {
          generateData(answerArr, answerIndex);
        });
      }

      console.log("finalArr", dataArr);
      console.log("JSONFinalArr", JSON.stringify(dataArr));

      function generateData(answerArr, answerIndex) {
        const countA = Math.round(200 * answerArr[0]);
        const countB = Math.round(200 * answerArr[1]);
        const countC = Math.round(200 * answerArr[2]);
        const countD = Math.round(200 * answerArr[3]);
        const countE = Math.round(200 * answerArr[4]);

        let arr = [];

        for (let i = 1; i <= countA; i++) {
          arr.push("A");
        }
        for (let i = 1; i <= countB; i++) {
          arr.push("B");
        }
        for (let i = 1; i <= countC; i++) {
          arr.push("C");
        }
        for (let i = 1; i <= countD; i++) {
          arr.push("D");
        }
        for (let i = 1; i <= countE; i++) {
          arr.push("E");
        }

        arr = arr.sort(() => Math.random() - 0.5); // 打乱顺序, 随机排序
        console.log("arr", arr);

        const numberA = getCountFromArr(arr, "A");
        const numberB = getCountFromArr(arr, "B");
        const numberC = getCountFromArr(arr, "C");
        const numberD = getCountFromArr(arr, "D");
        const numberE = getCountFromArr(arr, "E");

        console.log("arr中A的数量", numberA);
        console.log("arr中B的数量", numberB);
        console.log("arr中C的数量", numberC);
        console.log("arr中D的数量", numberD);
        console.log("arr中E的数量", numberE);

        console.log("=========>");

        console.log("arr中A的占比", numberA / 2);
        console.log("arr中B的占比", numberB / 2);
        console.log("arr中C的占比", numberC / 2);
        console.log("arr中D的占比", numberD / 2);
        console.log("arr中E的占比", numberE / 2);

        dataArr.forEach((item, index) => {
          item[`answer${answerIndex + 1}`] = arr[index];
        });
      }

      function getCountFromArr(arr, key) {
        let count = 0;
        arr.forEach((item) => {
          if (item === key) count += 1;
        });
        return count;
      }
    </script>
  </body>
</html>
